//
//  WSJCareNursingPeopleView.m
//  WSJCareNursingPeopleView
//
//  Created by wsj2015 on 16/4/8.
//  Copyright © 2016年 wsj2015. All rights reserved.
//

#import "WSJWaitingNursingPeopleView.h"
#import "WSJCareNursingPeopleCell.h"
#import "WSJSepctialBtn.h"
@interface WSJWaitingNursingPeopleView ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic,  strong) UICollectionView *collectionView;

@property (nonatomic,  strong) UICollectionViewFlowLayout *layout;

@property (nonatomic,  strong) WSJSepctialBtn *btn;

@property (nonatomic,  assign) BOOL isExpend;

@end

@implementation WSJWaitingNursingPeopleView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
//        self.backgroundColor =[UIColor redColor];
        UICollectionViewFlowLayout *layout =[[UICollectionViewFlowLayout alloc] init];
        layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        self.isExpend = NO;
        self.layout = layout;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        UICollectionView *coll =[[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.layout];
        coll.backgroundColor = [UIColor clearColor];
        self.collectionView = coll;
        [self.collectionView registerNib:[UINib nibWithNibName:@"WSJCareNursingPeopleCell" bundle:nil] forCellWithReuseIdentifier:@"WSJCareNursingPeopleCell"];
        coll.dataSource = self;
        coll.delegate = self;
        coll.alwaysBounceHorizontal = YES;
        [self addSubview:coll];
        self.btn =[WSJSepctialBtn buttonWithType:UIButtonTypeCustom];
        [self addSubview:self.btn];
        [self.btn addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

- (void)clickAction:(WSJSepctialBtn *)sender
{
    if (self.dataArray.count ==0) {
        return;
    }
    
    self.isExpend = !self.isExpend;
    if (self.expendBlock) {
        self.expendBlock(self.isExpend);
    }
    sender.enabled = NO;
    
    [UIView animateWithDuration:.35f animations:^{
         sender.myImageView.transform = CGAffineTransformRotate(sender.myImageView.transform, M_PI);
    } completion:^(BOOL finished) {
        sender.enabled = YES;
    }];
    
    
    
//    [self setNeedsLayout];
    CGFloat w =self.bounds.size.width;
    if (self.isExpend) {
        [UIView animateWithDuration:.35f animations:^{
            self.collectionView.frame =CGRectMake(0, 34, w, 98);
        }];
        
    }else{
        [UIView animateWithDuration:.35f animations:^{
            self.collectionView.frame =CGRectMake(0, 34, w, 0);
        }];
        
    }

}

- (void)layoutSubviews
{
    CGFloat w =self.bounds.size.width;
    CGFloat h =self.bounds.size.height;
    self.layout.itemSize = CGSizeMake(80, 98);
    self.layout.minimumInteritemSpacing =0;
    self.layout.minimumLineSpacing= 0;
//    self.collectionView.frame =CGRectMake(0, 34, w, 98);
    self.btn.frame = CGRectMake(0, 0, w, 34);
    self.collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
   
    [super layoutSubviews];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.dataArray) {
        return  self.dataArray.count;
    }
    return 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    WSJCareNursingPeopleCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"WSJCareNursingPeopleCell" forIndexPath:indexPath];
    cell.backgroundColor =[UIColor clearColor];
    id model = self.dataArray[indexPath.row];
    cell.tagImageView.hidden =YES;
    cell.deleBtn.hidden =YES;
    cell.model = model;
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}



@end
